home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / video / security / audio.C next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.3 KB  |  87 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. #include "audio.h"
  19. #include <stdio.h>
  20.  
  21. #ifdef DEBUG
  22. #define dprintf printf
  23. #else
  24. #define dprintf 0&& 
  25. #endif
  26.  
  27. Audio::Audio()
  28. {
  29.   long buf[32];
  30.   dprintf("Audio\n");
  31.   _numAudio = 0;
  32.   setRate(AL_RATE_8000);
  33.   setNumChannels(AL_MONO);
  34.   setBytesPerSample(AL_SAMPLE_16);
  35. // buffer 2 seconds of data
  36.   _bufferLength = getRate() * getNumChannels() * getBytesPerSample()  * 2;
  37.   _buffer = new char [_bufferLength];
  38.  
  39.   int n = 0;
  40.   buf[n++] = AL_INPUT_RATE;
  41.   buf[n++] = getRate();
  42.   buf[n++] = AL_OUTPUT_RATE;
  43.   buf[n++] = getRate();
  44.   buf[n++] = AL_INPUT_SOURCE;
  45.   buf[n++] = AL_INPUT_MIC;
  46. //  buf[n++] = AL_LEFT_INPUT_ATTEN;
  47. //  buf[n++] = 20;
  48. //  buf[n++] = AL_RIGHT_INPUT_ATTEN;
  49. //  buf[n++] = 20;
  50.   buf[n++] = AL_OUTPUT_RATE;
  51.   buf[n++] = getRate();
  52.   buf[n++] = AL_MIC_MODE;
  53.   buf[n++] = getNumChannels();
  54.   
  55.   ALsetparams(AL_DEFAULT_DEVICE, buf, n);
  56.   ALconfig config = ALnewconfig();
  57.   ALsetwidth(config,getBytesPerSample());
  58.   ALsetchannels(config,getNumChannels());
  59.   ALsetqueuesize(config, _bufferLength / getBytesPerSample());
  60.   _port = ALopenport("security","r",config);
  61.   ALfreeconfig(config);
  62. }
  63. Audio::~Audio()
  64. {
  65.   dprintf("end Audio\n");
  66.   ALcloseport(_port);
  67.   delete [] _buffer;
  68.   _port = NULL;
  69. }
  70.  
  71. void *
  72. Audio::getAudio(int &numSamples)
  73. {
  74.   dprintf("getAudio\n");
  75.   numSamples = int(ALgetfilled(_port));
  76.   if(numSamples > 0){
  77.     if(_bufferLength < numSamples * getBytesPerSample()){
  78.       delete [] _buffer;
  79.       _bufferLength = numSamples * getBytesPerSample();
  80.       _buffer = new char [_bufferLength ];
  81.     }
  82.     ALreadsamps(_port, _buffer, numSamples);
  83.     dprintf("getAudio %d\n",numSamples);
  84.     return _buffer;
  85.   }
  86. }
  87.